<script src="js/Calendar.js" type="text/javascript"></script>
<script type="text/javascript" src="js/global/Date_func.js"></script>
<link rel="stylesheet" type="text/css" href="css/member.css"/>
<style>
	.report{margin:10px 0; padding:15px; border:1px solid #eee}
	.report span.part{ margin-right:20px;}
	input.time{    background: url("images/rili.png") no-repeat scroll right center #FFFFFF;
    border: 1px solid #7F9DB9;
    height: 20px;
    line-height: 20px;
    width: 150px;}
	.total{ width:100%; text-align:center;}
	input.checkbox{ vertical-align:-2px; margin-right:2px;}
	.btn{ background:#eee; padding:4px 15px; *padding:4px 8px; background:url("images/mc_title.png") no-repeat right top; color:#fff; border:none; cursor:pointer}
	#excel{margin-left:10px;}
</style>
<h3 class="mc_title">
	<span class="mctit_1 <?=($from=="sale")?"":"notcur"?>">
		<a href="orderReport.html"><span class="mctit_2">已卖出产品报表</span></a>
	</span>
	<?if($_a->checkAuth("buyOrderReport.html")){?>
	<span class="mctit_1 <?=($from=="buy")?"":"notcur"?>">
		<a href="buyOrderReport.html"><span class="mctit_2">已买到产品报表</span></a>
	</span>
	<?}?>
    <span class="mctit_1 <?=($from=="alliance")?"":"notcur"?>">
		<a href="allianceOrderReport.html"><span class="mctit_2">已卖出联盟产品报表</span></a>
	</span>
</h3>
<form class="report" method="get">
	<input type="hidden" name="act" id="act" value=""/>
	<p>
		<span class="part">
			<input type="text" name="begintime" id="begintime" class="time" value="<?=$_GET['begintime']?>" onFocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
			<label>至</label>
			<input type="text" name="endtime" id="endtime" class="time" value="<?=$_GET['endtime']?>" onFocus="WdatePicker({startDate:'%y-%M-01 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
			<a href="javascript:changeDate('today');" class="sDate">今天</a>
			<a href="javascript:changeDate('yesterday');" class="sDate">昨天</a>
			<a href="javascript:changeDate('week');" class="sDate">本周</a>
			<a href="javascript:changeDate('lastweek');" class="sDate">上周</a>
			<a href="javascript:changeDate('month');" class="sDate">本月</a>
			<a href="javascript:changeDate('lastmonth');" class="sDate">上月</a>
		</span>
		<input type="submit" class="btn" value="查 询"/>
        <?/*if(!$access['yd']):?>
		<input type="button" id="excel" class="btn" value="导 出"/>
        <?endif;*/?>
	</p>
	<p style="margin:10px 0;">	
	<span  class="part">
		统计方式：
		<select name="by">
			<option value="">统计方式</option>
			<option value="province" <?=($_REQUEST['by']=="province")?"selected":""?>>按省代理统计</option>
            <option value="city" <?=($_REQUEST['by']=="city")?"selected":""?>>按市代理统计</option>
			<option value="lid" <?=($_REQUEST['by']=="lid")?"selected":""?>>按景区统计</option>
			<option value="tid" <?=($_REQUEST['by']=="tid")?"selected":""?>>按门票统计</option>
			<option value="mid" <?=($_REQUEST['by']=="mid")?"selected":""?>>按分销商统计</option>
		</select>
	</span>
    <span class="lt">查询条件：</span>
            联盟名称:
        <select name="alli_num">
            <option value="">请选择联盟</option>
			<?foreach($alli_names as $k=>$v){?>
			<option value="<?=$k?>" <?=($_REQUEST['alli_num']==$k)?"selected":""?>><?=$v?></option>
            <?}?>
		</select>
	</p>    
</form>
<div class="rank">
	<div class="rankcon">
		<table class="ranktab">
			<thead id="rankhd">
				<th>序号</th>
                <?if(!$_GET['by'] || $_GET['by']=='city' ||$_GET['by']=='province'){?>
                <th>联盟</th>
                <th>省</th>
                <th>省代理名称</th>
                <?}else{?>
                <th style="text-align:left" class="tL"><?=$titleT[$_GET['by']]?></th>
                <?}if($_GET['by']=='city'){?>
                <th>市</th>
                <th>市代理名称</th>
                <?}?>				
				<th><span class="sort" onclick="sortTable('offmain',2, true ,this);">订单数量</span></th>
				<th><span class="sort" onclick="sortTable('offmain',3, true ,this);">门票数量</span></th>
				<th><span class="sort" onclick="sortTable('offmain',4, true ,this);">金额</span></th>
				<th><span class="sort" onclick="sortTable('offmain',5, true ,this);">余额支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',6, true ,this);">在线支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',7, true ,this);">授信支付</span></th>
				<th><span class="sort" onclick="sortTable('offmain',8, true ,this);">产品自销</span></th>
				<th><span class="sort" onclick="sortTable('offmain',8, true ,this);">现场支付</span></th>
			</thead>
			<tbody id="offmain">
				<?
                if(count($result)){
                foreach($result as $fid_num=>$val){
                   foreach($val as $k=>$row){
                        if(empty($row['order'])) continue;
                        $totals['order']+=$row['order'];
                        $totals['tnum']+=$row['tnum'];
                        $totals['money']+=$row['money']/100;
                        $totals['pmode0']+=$row['pmode0']/100;
                        $totals['pmode1']+=$row['pmode1']/100;
                        $totals['pmode2']+=$row['pmode2']/100;
                        $totals['pmode3']+=$row['pmode3']/100;
                        $totals['pmode4']+=$row['pmode4']/100;
				?>
				<tr>
					<td><?=++$n?></td>
                    <?if(!$_GET['by'] || $_GET['by']=='city' ||$_GET['by']=='province'){?>                    
                    
                        <td><?=$alli_names[$fid_num]//联盟名称?></td>
                        <td class="tL"><?=$row['title']//省?></td>
                        <td><?=$agency[$row['agency_p']]//省代理?></td>
                                                
                    <?}else{?>
                    
                        <td class="tL"><?=$row['title']?></td>
                        
                    <?}if($_GET['by']=='city'){?>
                    
                        <td><?=$row['city']?></td>
                        <td><?=$agency[$row['agency_c']]?></td>
                        
                    <?}?>	
                    <td><?=$row['order']?></td>
					<td><?=$row['tnum']?></td>
					<td><?=$row['money']/100?></td>
					<td><?=$row['pmode0']/100?></td>
					<td><?=$row['pmode1']/100?></td>
					<td><?=$row['pmode2']/100?></td>
					<td><?=$row['pmode3']/100?></td>
					<td><?=$row['pmode4']/100?></td>
				</tr>
				<?}}}?>
			</tbody>
			<tfoot>
			<?if(count($result)>0){?>
				<tr>
					<td>总计：</td>
					<?if(!$_GET['by'] || $_GET['by']=='city' ||$_GET['by']=='province'){?>
                    <td></td>
                    <td></td>
                    <td></td>
                    <?}else{?>
                    <td></td>
                    <?}if($_GET['by']=='city'){?>
                    <td></td>
                    <td></td>
                    <?}?>	
                    <td><?=$totals['order']?></td>
					<td><?=$totals['tnum']?></td>
					<td><?=$totals['money']?></td>
					<td><?=$totals['pmode0']?></td>
					<td><?=$totals['pmode1']?></td>
					<td><?=$totals['pmode2']?></td>
					<td><?=$totals['pmode3']?></td>
					<td><?=$totals['pmode4']?></td>
				</tr>
			<?}else{?>
				<tr>
					<td align="left" colspan="9">&nbsp;&nbsp;&nbsp;交易日期无销售订单！</td>
				</tr>
			<?}?>
			</tfoot>
		</table>
	</div>
</div>

<script src="js/jsorder.js"></script>
<script src="http://www.12301.cc/js/WdatePicker.js"></script>
<script>
	$("#time").change(function(){
		Date_func.selectDate($(this).val(),$("#begintime").get(0),$("#endtime").get(0));
	});
	$("input.btn").click(function(){
		var btime=$("#begintime").val();
		var etime=$("#endtime").val();
		btime=btime.split("-");
		etime=etime.split("-");
		month=(etime[0]-btime[0])*12+(etime[1]-btime[1]);
		if(month>3){
			alert("交易日期时间间隔不能超过三个月");
			return false;
		}
	});
	// 获取门票
	$("#land").change(function(){
		
		landid=$(this).val();
		if(landid==''){
			_options = '<option value="">--选择--</option>';
			$("#ticket").html(_options);
			return;
		}
		$.ajax({
			uri:window.location.href,
			data:"landid="+landid,
			beforeSend:function (XMLHttpRequest) {
				XMLHttpRequest.setRequestHeader("request_type","getTicket");
			},
			success: function(data){
				data = JSON.parse(data);
				if(data.s=='success'){
					_options = '<option value="">--选择--</option>';
					for(var i in data.content){
						_options+='<option value="'+data.content[i].id+'_'+data.content[i].title+'">'+data.content[i].title+'</option>';
					}
					$("#ticket").html(_options);

				}
			}
		});
	});
	
	$("#excel").click(function(){
		$("#act").val("orderReportExcel");
		$("form.report").submit();
		$("#act").val("");
	});
	
	function changeDate(date){
		// lastweek颠倒了
		if(date=='lastweek'){
			Date_func.selectDate(date,$("#endtime").get(0),$("#begintime").get(0));
		}else{
			Date_func.selectDate(date,$("#begintime").get(0),$("#endtime").get(0));
		}
	}

   

</script>